package ru.pb.game.objects.model.items.tasks;

import ru.pb.game.dao.ItemsDAO;
import ru.pb.game.objects.model.items.Item;
import ru.pb.game.objects.storage.ObjectsStorage;
import ru.pb.global.dao.DAOManager;
import ru.pb.global.threading.RunnableTask;

/**
 * @author Felixx
 */
public class LazyUpdateInDb extends RunnableTask
{
	private static final ItemsDAO _dao = DAOManager.getDAOImpl(ItemsDAO.class);
	private final long _itemStoredId;

	public LazyUpdateInDb(Item item)
	{
		_itemStoredId = item.getStoredId();
	}

	@Override
	public void runImpl()
	{
		Item item = ObjectsStorage.getInstance().getAsItem(_itemStoredId);

		if(item == null)
		{
			return;
		}

		try
		{
			_dao.insert(null, item);
		}
		finally
		{
			item.stopLazyUpdateTask(false);
		}
	}
}